class GenRuleKey(object):
  def __init__(self, dirname, rulename, variant):
    self.dirname = dirname # string
    self.rulename = rulename # string
    self.variant = variant # string
    assert type(self.variant) == str
    self.__hash = hash(self.tuple_key())

  def full_name(self):
    if self.dirname == '.':
      return '//:' + self.rulename
    else:
      return "//" + self.basic_full_name()

  def basic_full_name(self):
    return self.dirname + ":" + self.rulename

  def tuple_key(self):
    return (self.dirname, self.rulename, self.variant)
  def __hash__(self):
    return self.__hash
  def __eq__(self, other):
    return (isinstance(other, GenRuleKey) and
            self.tuple_key() == other.tuple_key())

  def __repr__(self):
    return "<GenRule: " + repr(self.tuple_key()) + ">"

class FileSetKey(object):
  def __init__(self, genrule_key, bucket_name, name):
    self.genrule_key = genrule_key # GenRuleKey
    self.bucket_name = bucket_name # string
    self.name = name # string
    self.__hash = hash(self.tuple_key())

  def tuple_key(self):
    return (self.genrule_key, self.bucket_name, self.name)

  def __repr__(self):
    return ("<FileSet: " + repr(self.tuple_key()) + ">")

  def __str__(self):
    return repr(self)

  def fset_name(self):
    return (self.genrule_key.basic_full_name() + "#" + 
        self.bucket_name + "." + self.name)

  def __hash__(self):
    return self.__hash

  def __eq__(self, other):
    return (isinstance(other, FileSetKey) and
            self.tuple_key() == other.tuple_key())

class FileKey(object):
  def __init__(self, fname):
    self.fname = fname # string

  def __repr__(self):
    return "<File: " + self.fname + ">"

  def __str__(self):
    return self.fname

  def __hash__(self):
    return hash(self.fname)

  def __eq__(self, other):
    return (isinstance(other, FileKey) and 
        self.fname == other.fname)

class BuildFileKey(object):
  def __init__(self, fname):
    self.fname = fname # string

  def __repr__(self):
    return "<BUILD: " + self.fname + ">"

  def __str__(self):
    return self.fname

  def __hash__(self):
    return hash(self.fname)

  def __eq__(self, other):
    return (isinstance(other, BuildFileKey) and 
            self.fname == other.fname)

class GenericGraphKey(object):
  def __init__(self, keyval):
    self.keyval = keyval

  def __repr__(self):
    return self.keyval

  def __hash__(self):
    return hash(self.keyval)

  def __eq__(self, other):
    return (isinstance(other, GenericGraphKey) and
        self.keyval == other.keyval)
